using System;
using System.Drawing;
using System.Collections.Generic;
using System.Text;

namespace ClientGUI.Modules.Drawing
{
    /// <summary>
    /// Display a simple rectangle with a background color.
    /// </summary>
    public class RectangleDisplayArea : DisplayArea
    {
        /// <summary>
        /// Background color of this
        /// </summary>
        protected Color background;

        /// <summary>
        /// Size of this rectangle.
        /// </summary>
        protected Rectangle region;

        /// <summary>
        /// Determines which edges get lignt lines drawn
        /// </summary>
        protected RectangleVisible lightVisible;

        /// <summary>
        /// Determines which edges get dark lines drawn
        /// </summary>
        protected RectangleVisible darkVisible;


        /// <summary>
        /// Pen for the light lines
        /// </summary>
        Pen lightPen;

        /// <summary>
        /// Pen for the dark lines
        /// </summary>
        Pen darkPen;

        /// <summary>
        /// A rectangle display area
        /// </summary>
        /// <param name="backColor">Background color</param>
        /// <param name="area">Size of this rectangle</param>
        /// <param name="darkPenP">Dark line pen</param>
        /// <param name="lightPenP">Light line pen</param>
        /// <param name="darkSides">Dark sides to draw</param>
        /// <param name="lightSides">Light sides to draw</param>
        public RectangleDisplayArea(Color backColor, Rectangle area, Pen darkPenP, Pen lightPenP, RectangleVisible darkSides, RectangleVisible lightSides)
        {
            background = backColor;
            region = area;
            lightPen = lightPenP;
            darkPen = darkPenP;
            lightVisible = lightSides;
            darkVisible = darkSides;
        }

        /// <summary>
        /// Draw a rectangle onto the specified region
        /// </summary>
        /// <param name="displayArea">Area to draw on</param>
        /// <param name="cr">Clip Region</param>
        /// <param name="offset"></param>
        public override void Composite(Graphics displayArea, Rectangle cr, Point offset)
        {
            Rectangle cr2 = new Rectangle(
                offset.X,
                offset.Y,
                cr.Width,
                cr.Height);
#if DEBUG
            Console.WriteLine("RectangleDisplayArea.Composite: ClipRegion: " + cr);
            Console.WriteLine("RectangleDisplayArea.Composite: Offset: " + offset);
            Console.WriteLine("RectangleDisplayArea.Composite: DisplayClipRegion: " + cr2);
#endif

            //displayArea.DrawRectangle(new Pen(Color.Red), cr2);
            displayArea.FillRectangle(new SolidBrush(background), new Rectangle(offset.X, offset.Y, 10, cr.Height));

            Point left_top = new Point(cr2.X, cr2.Y);
            Point left_bottom = new Point(cr2.X, cr2.Bottom);
            Point right_top = new Point(cr2.Right, cr2.Y);
            Point right_bottom = new Point(cr2.Right, cr2.Bottom);

            //left
            //displayArea.DrawLine(pen, left_top, left_bottom);

            //right
            if (lightVisible.Right)
            {
                displayArea.DrawLine(lightPen, right_top, right_bottom);
            }

            //left
            if (lightVisible.Left)
            {
                displayArea.DrawLine(lightPen, left_top, left_bottom);
            }



            //top
            if (darkVisible.Top)
            {
                displayArea.DrawLine(darkPen, left_top, right_top);
            }

            //bottom
            if (darkVisible.Bottom)
            {
                displayArea.DrawLine(darkPen, left_bottom, right_bottom);
            }

            //right
            if (darkVisible.Right)
            {
                displayArea.DrawLine(darkPen, right_top, right_bottom);
            }

            //left
            if (lightVisible.Left)
            {
                displayArea.DrawLine(lightPen, left_top, left_bottom);
            }



            if (cr.X == 0)
            {
                //top
                if (lightVisible.Top)
                {
                    displayArea.DrawLine(lightPen, left_top, right_top);
                }
            }
            if (cr.Bottom >= this.region.Height)
            {
                //bottom
                if (lightVisible.Bottom)
                {
                    displayArea.DrawLine(lightPen, left_bottom, right_bottom);
                }
            }
#if DEBUG
            Console.WriteLine("RectangleDisplayArea.Composite: Drew Right:  (" + right_top + ", " + right_bottom + ")");
            Console.WriteLine("RectangleDisplayArea.Composite: Drew Left:   (" + left_top + ", " + left_bottom + ")");
#endif


#if DEBUG
                    Console.WriteLine("RectangleDisplayArea.Composite: Drew Top:    (" + left_top + ", " + right_top + ")");
                    Console.WriteLine("RectangleDisplayArea.Composite: Drew Bottom: (" + left_bottom + ", " + right_bottom + ")");
#endif

        }
    }
}
